<?php
	require '../../include/library.inc.php';
	require '../../include/admin_login.inc.php';
	require '../../include/paging.inc.php';
	
	
	$sql = "SELECT
				c.project_id,
				c.creation_time,
				c.order_number,
				c.published,
				c.top,
				c.cover,
				c.cover_class,
				
				
				d.title
				
			FROM
				projects AS c,
				project_description AS d ";
	
	if($_GET['cat_id']){
			$sql .= ",project_to_category AS p2c  ";
		}
	
	
	$sql .=	"WHERE
				c.type = 'project'
				AND
				c.project_id = d.project_id
				
				AND
				
				d.lang_id = '1'
			  ";
	if($_GET['cat_id']){
			$sql .= "AND p2c.category_id = '".intval($_GET['cat_id'])."'
			AND p2c.project_id = c.project_id ";
		}		  

	
	if (!isset($_GET['sort'])) $_GET['sort'] = 1;
	if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 3;
	
	$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(3=>"Подредба"), 30);
	$result = $paging->query();
		
		head_admin("Проекти");
	?>
			
				<?php if ($_SESSION['message']) { ?>
				<div class="message green">
					<?=$_SESSION['message']?>
				</div>
				<?php unset($_SESSION['message']); } ?>
			
			
				<div class="topbuttons">
					<a href="project_new.php">Добави нов проект</a>
					
				</div>
				<h3>Проекти (<?=$paging->count()?>)</h3>
				
				<table id="listing" width="100%" cellpadding="0" cellspacing="0">
					<thead>
                        <tr>
                        	<td width="310px">Име</td>
                            <td>Оформление</td>
                            <td>Top</td>
                            <td>Публикуван</td>
                            <td>подердба</td>
                            <td>Действия</td>
                        </tr>
                    </thead>
				<tbody>
				<?php
				  
				  
				  $i=1;
				  while ($row = mysql_fetch_object($result)) {				  
				?>
						<tr class="<?=(($i%2)?"none":"zebra")?>">
                        
                        	<td >
                            <a href="project_edit.php?project_id=<?=$row->project_id?>" title="Редактирай">
                            <?=sth($row->title)?><br />

                            <div id="img_<?=$row->project_id?>" class="<?=$row->cover_class?>" style="background-image:url(../project_images/medium/<?=$row->cover?>)"></div>
                            </a>
                            </td>
                            
							<td>
                            	
                        <select onchange="$('#img_<?=$row->project_id?>').attr('class', $(this).val()); saveCoverClass('<?=$row->project_id?>');" class="inputbox" style="width:180px"  id="image_class_<?=$row->project_id?>">
                    	<option value="col650_300" <?php if($row->cover_class == 'col650_300') echo 'selected="selected"';?> >хоризонтална</option>
                        <option value="col300_650" <?php if($row->cover_class == 'col300_650') echo 'selected="selected"';?> >вертикална</option>
                        <option value="col300_300" <?php if($row->cover_class == 'col300_300') echo 'selected="selected"';?> >квадрат</option>
                    </select>
                                
                                
							<td class="switch">
								<?php if ($row->top) { ?>
								 <a href="project_top.php?project_id=<?=$row->project_id?>&top=0" class="turn_on" name="turn_on" title="Спри"></a>
								<?php } else { ?> 
								 <a href="project_top.php?project_id=<?=$row->project_id?>&top=1" class="turn_off" name="turn_off" title="Покажи на първа страница"></a>
								<?php } ?>	
							</td>
                            
                            
                            <td class="switch">
								<?php if ($row->published) { ?>
								 <a href="project_publish.php?project_id=<?=$row->project_id?>&publish=0" class="turn_on" name="turn_on" title="Спри"></a>
								<?php } else { ?> 
								 <a href="project_publish.php?project_id=<?=$row->project_id?>&publish=1" class="turn_off" name="turn_off" title="Публикувай"></a>
								<?php } ?>	
							</td>
							
							<td class="sort">
								<?php if ($i != 1) { ?>
								<a name="Up" class="sorting_up" title="Нагоре" href="project_direction.php?project_id=<?=$row->project_id?>&direction=1&type=project"></a>
								<?php } ?>							
								<?php if ($i != ($paging->count())) { ?>
								<a name="Down" class="sorting_down" title="Надолу" href="project_direction.php?project_id=<?=$row->project_id?>&direction=-1&type=project"></a>
								<?php } ?>
								&nbsp;<!--ie6 bug-->
							</td>
							
							<td class="icons">
								<a name="Top" class="sorting_top" title="Top" href="project_direction.php?project_id=<?=$row->project_id?>&top=1&type=project">Top</a>
								
								
								<a href="project_edit.php?project_id=<?=$row->project_id?>" class="edit" title="Редактирай">Редактирай</a> 
								<a onClick="if (window.confirm('Сигурен ли си, че искаш да изтриеш <?=sth($row->title)?>?')) { document.location='project_del.php?project_id=<?=$row->project_id?>'; return false; }" class="delete" title="Изтрий">Изтрий</a>
							</td>
							
						</tr>
			 <?php
				  $i++;    
				} 
			 ?>				  
				</tbody>
			</table>
			
			<div class="pagingwrap"><div class="paging">
				<?=$paging->display()?>
			</div></div>
            
            
                 <script type="text/javascript">
		
		function saveCoverClass(id)
		{
			
			$.ajax({
					type: 'POST',
					url: 'album_ajax_class.php',
					data: 'cover_class='+$("#image_class_"+id).val()+'&project_id='+id,
					success: function(msg){
						
						//alert(msg);
						$('.imsg').remove();
						$('#img_'+id).html('<p class="imsg" style="background:#0C6; padding:5px 10px;">'+msg+'</p>');
						$('.imsg').delay(4000).slideUp(100);
						
					},
					error: function(msg){
						alert('Err:'+ msg)
					}
				});
		}
	
		
		

</script>
<?php
	foot_admin(); 
?>